<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/order.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons"><a onclick="location = '<?php echo $insert; ?>'" class="button"><?php echo $button_insert; ?></a></div>
    </div>
    <div class="content">
        <table class="list">
          <thead>
            <tr>
              <td class="center"><?php echo $column_promotion_id; ?></td>
              <td class="center"><?php echo $column_name; ?></td>
              <td class="center"><?php echo $column_display_name; ?></td>
              <td class="center"><?php echo $column_description; ?></td>
              <td class="center"><?php if ($sort == 'start_time') { ?>
                <a href="<?php echo $sort_start_time; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_start_time; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_start_time; ?>"><?php echo $column_start_time; ?></a>
                <?php } ?></td>
              <td class="center"><?php if ($sort == 'end_time') { ?>
                <a href="<?php echo $sort_end_time; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_end_time; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_end_time; ?>"><?php echo $column_end_time; ?></a>
                <?php } ?></td>
              <td class="center"><?php if ($sort == 'status') { ?>
                <a href="<?php echo $sort_status; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_status; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_status; ?>"><?php echo $column_status; ?></a>
                <?php } ?></td>
              <td class="center"><?php echo $column_image; ?></td>
              <td class="center"><?php echo $column_action; ?></td>
            </tr>
          </thead>
          <tbody>
            <tr class="filter">
              <td class="left"><input type="text" name="filter_promotion_id" value="<?php echo $filter_promotion_id; ?>" size="11"/></td>
              <td class="left"><input type="text" name="filter_name" value="<?php echo $filter_name; ?>" /></td>
              <td class="left"></td>
              <td class="left"></td>
              <td class="left"><input type="text" name="filter_start_time" value="<?php echo $filter_start_time; ?>" size="12" class="date" /></td>
              <td class="left"><input type="text" name="filter_end_time" value="<?php echo $filter_end_time; ?>" size="12" class="date" /></td>
              <td class="left">
                <input type="radio" name="filter_status" value="-1" <?php if ($filter_status != 0 && $filter_status != 1){ echo 'checked="checked"';} ?> /><?php echo $text_status_all; ?>
              	<input type="radio" name="filter_status" value="1" <?php if ($filter_status == 1){ echo 'checked="checked"';} ?> /><?php echo $text_status_yes; ?>
                <input type="radio" name="filter_status" value="0" <?php if ($filter_status == 0){ echo 'checked="checked"';} ?> /><?php echo $text_status_no; ?>
              </td>
              <td class="left"></td>
              <td align="right"><a onclick="filter();" class="button"><?php echo $button_filter; ?></a></td>
            </tr>
            <?php if ($promotions) { ?>
            <?php foreach ($promotions as $promotion) { ?>
            <tr>
              <td class="left"><?php echo $promotion['promotion_id']; ?></td>
              <td class="left"><?php echo $promotion['name']; ?></td>
              <td class="left"><?php echo $promotion['display_name']; ?></td>
              <td class="left"><?php echo $promotion['description']; ?></td>
              <td class="left"><?php echo $promotion['start_time']; ?></td>
              <td class="left"><?php echo $promotion['end_time']; ?></td>
              <td class="left">
              	<?php if ($promotion['status'] == '0') { echo $text_status_no;} else { echo $text_status_yes; } ?>
              </td>
              <td class="left"><img src="<?php echo $promotion['image']; ?>"></td>
              <td class="right"><?php foreach ($promotion['action'] as $action) { ?>
                [ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ]
                <?php } ?></td>
            </tr>
            <?php } ?>
            <?php } else { ?>
            <tr>
              <td class="center" colspan="9"><?php echo $text_no_results; ?></td>
            </tr>
            <?php } ?>
          </tbody>
        </table>
      <div class="pagination"><?php echo $pagination; ?></div>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
function filter() {
	url = 'index.php?route=sale/promotion&token=<?php echo $token; ?>';
	
	var filter_id = $('input[name=\'filter_id\']').attr('value');
	if (filter_id) {
		url += '&filter_id=' + encodeURIComponent(filter_id);
	}
	
	var filter_name = $('input[name=\'filter_name\']').attr('value');
	if (filter_name) {
		url += '&filter_name=' + encodeURIComponent(filter_name);
	}
	
	var filter_status = $('input[name=\'filter_status\']:checked').attr('value');
	if (filter_status != '-1') {
		url += '&filter_status=' + encodeURIComponent(filter_status);
	}	

	var filter_startTime = $('input[name=\'filter_start_time\']').attr('value');
	if (filter_startTime) {
		url += '&filter_start_time=' + encodeURIComponent(filter_startTime);
	}
	
	var filter_endTime = $('input[name=\'filter_end_time\']').attr('value');
	if (filter_endTime) {
		url += '&filter_end_time=' + encodeURIComponent(filter_endTime);
	}
	location = url;
}
//--></script>  
<script type="text/javascript"><!--
$(document).ready(function() {
	$('.date').datepicker({dateFormat: 'yy-mm-dd'});
});
//--></script> 
<script type="text/javascript"><!--
$('#form input').keydown(function(e) {
	if (e.keyCode == 13) {
		filter();
	}
});
//--></script>
<?php echo $footer; ?>